﻿using System.Linq;
using iss.sg4210.se18.team6s.jass.DAL.DataAccess.Interfaces;

namespace iss.sg4210.se18.team6s.jass.DAL.DataAccess.MSSQL
{
    public class SkillsDAO : ObjectDAO, ISkills
    {
        public SkillsDAO() : base() { }

        public System.Linq.IQueryable<Skill> FindAllSkills()
        {
            return jassEntities.Skills;
        }

        public Skill GetSkill(int skillId)
        {
            return jassEntities.Skills.SingleOrDefault(c => c.Id == skillId);
        }

        public void AddSkill(Skill skill)
        {
            jassEntities.AddToSkills(skill);
            Save();
        }

        public void UpdateSkill(Skill skill)
        {
            jassEntities.Skills.ApplyCurrentValues(skill);
            Save();
        }

        public void DeleteSkill(int skillId)
        {
            Skill skill = GetSkill(skillId); ;
            jassEntities.Skills.DeleteObject(skill);
            Save();
        }
    }

    public class SkillTypeDAO : ObjectDAO, ISkillType
    {
        public SkillTypeDAO() : base() { }

        public System.Linq.IQueryable<SkillType> FindAllSkillTypes()
        {
            return jassEntities.SkillTypes;
        }

        public SkillType GetSkillType(int skillTypeId)
        {
            return jassEntities.SkillTypes.SingleOrDefault(c => c.Id == skillTypeId);
        }

        public void AddSkillType(SkillType skillType)
        {
            jassEntities.AddToSkillTypes(skillType);
            Save();
        }

        public void UpdateSkillType(SkillType skillType)
        {
            jassEntities.SkillTypes.ApplyCurrentValues(skillType);
            Save();
        }

        public void DeleteSkillType(int skillTypeId)
        {
            SkillType skillType = GetSkillType(skillTypeId); ;
            jassEntities.SkillTypes.DeleteObject(skillType);
            Save();
        }
    }
}
